Skip to content

feat: Stable system prompt and tool ordering for more cache hits#5192

Merged
jsibbison-square merged 10 commits intomainfrom
jsibbison-20251015-no-dynamic-system-prompt
Oct 20, 2025
Merged

feat: Stable system prompt and tool ordering for more cache hits#5192
jsibbison-square merged 10 commits intomainfrom
jsibbison-20251015-no-dynamic-system-prompt

Conversation

@jsibbison-square
Copy link
Contributor

@jsibbison-square jsibbison-square commented Oct 15, 2025

Summary

When running multiple goose instances for the same tasks (eg. recipes) we currently do not get any llm cache hits on the initial request. From my testing this happens for multiple reasons:

  • We have a second-based timestamp in the system prompt
  • Tools are added in a random order
  • Extension instructions come in a random order

This PR makes the timestamp truncated at the hour to allow for decent time accuracy but greatly improved cache hit potential and sorts the extensions (for instructions) and tools by name so they always appear in the same order.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

Testing

I've used an api key with openai and downloaded their usage csv to verify that caching on the same initial request run in subsequent sessions with the developer mcp results in almost 100% cached input token usage.

@jsibbison-square jsibbison-square marked this pull request as ready for review October 15, 2025 23:56
Updated comment to clarify prompt cache behavior.
Copy link
Collaborator

@DOsinga DOsinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @tlongwell-block is also looking at some of this

}

#[test]
fn test_build_system_prompt_orders_extensions_by_name() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was useful to avoid regressing but have deleted it.

@tlongwell-block
Copy link
Collaborator

Yeah, #5027 removes the timestamp entirely from the system prompt

@jsibbison-square
Copy link
Contributor Author

jsibbison-square commented Oct 16, 2025

@tlongwell-block So should I just delete the timestamp line in this PR so we get caching sooner or do you want me to not make that change and have your PR do that? I matched your change to delete the timestamp for system_prompt.md so shouldn't conflict when it merges

Once you respond I'll be able to merge.

…com:block/goose into jsibbison-20251015-no-dynamic-system-prompt

* 'jsibbison-20251015-no-dynamic-system-prompt' of github.com:block/goose:
  Clarify comment on prompt cache filtering
@tlongwell-block
Copy link
Collaborator

@tlongwell-block So should I just delete the timestamp line in this PR so we get caching sooner or do you want me to not make that change and have your PR do that? I matched your change to delete the timestamp for system_prompt.md so shouldn't conflict when it merges

Once you respond I'll be able to merge.

Until #5027 is merged, this would mean goose won't know the time at all

@DOsinga, what do you think about merging #5027 right after this one? If we're still not sure about MOIM as a concept, I'd say leave the timestamp in here @jsibbison-square. I will say that the MOIM build is my daily driver and works very well, including on the benchmarks.

@jsibbison-square
Copy link
Contributor Author

Ok I'll put the timestamp back at just the hourly granuality that way we get greater caching and you don't need to rush the other PR.

You are a general-purpose AI agent called goose, created by Block, the parent company of Square, CashApp, and Tidal.
goose is being developed as an open-source software project.

The current date is {{current_date_time}}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could consider adding this to the end so we get most of the system prompt cached

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will leave it unchanged here so tylers pr doesn't get a conflict when he removes the timestamp (we changed the timestamp to be at an hour granuality so we still get improved caching benefits).

@jsibbison-square jsibbison-square merged commit e9ca2bc into main Oct 20, 2025
11 checks passed
@jsibbison-square jsibbison-square deleted the jsibbison-20251015-no-dynamic-system-prompt branch October 20, 2025 21:48
tlongwell-block added a commit that referenced this pull request Oct 20, 2025
- Includes stable system prompt and tool ordering (#5192)
- Memory extension prompt updates (#4945)
- Smart task organizer recipe (#5032)
- Recipe open command docs (#5264)
- Various provider and UI updates
michaelneale added a commit that referenced this pull request Oct 21, 2025
* main:
  Fix extension manager resource deadlock (#5066)
  add new prompt for memory extension (#4945)
  feat: Stable system prompt and tool ordering for more cache hits (#5192)
  Remove gtag analytics error (#5268)
  Feat/smart task organizer recipe (#5032)
  docs: `goose recipe open` command (#5264)
  docs: provide more clarity in tagging step of releases (#5269)
  docs: add GOOSE_DEBUG environment variable (#5265)
michaelneale added a commit that referenced this pull request Oct 21, 2025
* main: (40 commits)
  Fix extension manager resource deadlock (#5066)
  add new prompt for memory extension (#4945)
  feat: Stable system prompt and tool ordering for more cache hits (#5192)
  Remove gtag analytics error (#5268)
  Feat/smart task organizer recipe (#5032)
  docs: `goose recipe open` command (#5264)
  docs: provide more clarity in tagging step of releases (#5269)
  docs: add GOOSE_DEBUG environment variable (#5265)
  Lifei/UI parameter input (#5222)
  turn off WAL (#5203)
  Skip subagents for gemini (#5257)
  Revert "Standardize Session Name Attribute" (#5250)
  improve provider request logging a bit (#5236)
  Fix OpenAI empty choices panic (#5248)
  Revert "Rewrite extension management tools" (#5243)
  Standardize Session Name Attribute (#5085)
  Docs: Include step-by-step model configuration instructions for first… (#5239)
  Delete message visibility filter (#5216)
  delete flaky pricing integration tests (#5207)
  chore: upgrade most npm packages to latest (#5185)
  ...
michaelneale added a commit that referenced this pull request Oct 21, 2025
* main:
  live testing script (#5263)
  Fix extension manager resource deadlock (#5066)
  add new prompt for memory extension (#4945)
  feat: Stable system prompt and tool ordering for more cache hits (#5192)
  Remove gtag analytics error (#5268)
  Feat/smart task organizer recipe (#5032)
  docs: `goose recipe open` command (#5264)
  docs: provide more clarity in tagging step of releases (#5269)
  docs: add GOOSE_DEBUG environment variable (#5265)
katzdave added a commit that referenced this pull request Oct 21, 2025
* 'main' of github.com:block/goose:
  fix: include Windows GNU CLI artifact in releases (#5276)
  Fix bedrock tool call error response (#5067)
  fix: do not load active extensions when no extensions in the recipe (#5282)
  Fix pagination - fetch all open issues, not just first 100
  Fix label case sensitivity - use lowercase labels
  Add GitHub Health Dashboard workflow (#5286)
  live testing script (#5263)
  escaping markdown
  fixing syntax
  Add GitHub Health Dashboard workflow
  Fix extension manager resource deadlock (#5066)
  add new prompt for memory extension (#4945)
  feat: Stable system prompt and tool ordering for more cache hits (#5192)
  Remove gtag analytics error (#5268)
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Oct 25, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants